angular.module('ceo', ['ionic', 'angular-meteor','angularMoment','ngCordova',
  'chart.js',
  'ceo.router','ceo.controllers', 'ceo.services',
  'global','common','base','department','employee','product',
  'sale','inventory',
  'supplier','purchasing','chat'
])

.run(function($ionicPlatform,amMoment,$rootScope,$ionicPopup,$cordovaNetwork,StatusBarService,BackButtonService) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }

    StatusBarService.setStyle();
    BackButtonService.registerBackButtonAction();
  });
  // moment插件本地化
  amMoment.changeLocale('zh-cn');

  //全局配置
  $rootScope.hasFilter = false;
  $rootScope.showEdit = false;
  $rootScope.isEdit = false;
  $rootScope.toggleEdit = function(){ //callback
    $rootScope.isEdit = !$rootScope.isEdit;
  };

  // 切换state
  $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options) {
    // 重置全局编辑状态
    $rootScope.isEdit = false;

    //检查是否还在线,网络是否正常
    if (window.cordova){
      var type = $cordovaNetwork.getNetwork();
      var isOnline = $cordovaNetwork.isOnline();
    }

    if ($rootScope.currentUser===null) {
      $ionicPopup.alert({
        title: '登录超时',
        template: '请您重新登录',
        // cancelText: '取消',
        okText: '确定'
      }).then(function (res) {
        setTimeout(function () {
          window.location.href='index.html';
        }, 500);

      });
    }

  });

})

.config(function($stateProvider,$urlRouterProvider,$ionicConfigProvider,ChartJsProvider) {
  $ionicConfigProvider.backButton.text('');
  $ionicConfigProvider.backButton.previousTitleText(false);

  $ionicConfigProvider.views.maxCache(50); 
  $ionicConfigProvider.views.swipeBackEnabled(false);
  ChartJsProvider.setOptions({
    colours: ['#FF7800', '#387ef5', '#11c1f3', '#33cd5f', '#ffc900', '#ef473a'],
    animationEasing : "easeInOutQuart"
  });
  ChartJsProvider.setOptions('Bar', {
    animationEasing : "easeOutBounce"
  });

  $ionicConfigProvider.tabs.style('standard');
  $ionicConfigProvider.tabs.position('bottom');

});
